import Vue from 'vue'
import Router from 'vue-router'
import home from './components/home.vue'
import login from './components/login.vue'
import welcome from './components/welcome.vue'
import user_edit from './components/user_edit.vue'
import myprofile from './components/myprofile.vue'
import add_user from './components/add_user.vue'
import add_goods_type from './components/add_goods_type.vue'
import add_order from './components/add_order.vue'
import add_customer from './components/add_customer.vue'
import add_company from './components/add_company.vue'
import order_list from './components/order_list.vue'
import customer_list from './components/customer_list.vue'
import order_message from './components/order_message.vue'
import add_tag from './components/add_tag.vue'
import goods_type from './components/goods_type.vue'
import tag_list from './components/tag_list.vue'
import dashboard from './components/dashboard.vue'
import monitoring from './components/monitoring.vue'

Vue.use(Router)


export default new Router({
    mode: 'history',
    routes: [{
        path: '/',
        name: 'home',
        component: home,
        beforeEnter: (to, from, next) => {
            //判断是否登录
            if (localStorage.getItem('uid')) {
                console.log('已登录');
                next();
            } else {
                console.log('未登录');
                // 使用next进行重新定向到登陆页面
                next('/login');
            }
        },
        redirect: '/dashboard',
        children: [
            { path: '/welcome', component: welcome },
            { path: '/user_edit', component: user_edit },
            { path: '/myprofile', component: myprofile },
            { path: '/add_user', component: add_user },
            { path: '/add_goods_type', component: add_goods_type },
            { path: '/add_order', component: add_order },
            { path: '/add_customer', component: add_customer },
            { path: '/add_company', component: add_company },
            { path: '/order_list', component: order_list },
            { path: '/customer_list', component: customer_list },
            { path: '/order_message', component: order_message },
            { path: '/add_tag', component: add_tag },
            { path: '/goods_type', component: goods_type },
            { path: '/tag_list', component: tag_list },
            { path: '/dashboard', component: dashboard },
            { path: '/monitoring', component: monitoring },
        ]
    }, {
        path: '/login',
        component: login
    }, ]
})